<?php

/*
 * Config
 */
require_once '../htdocs/public/config/settings.inc.php';
$database = _DB_NAME_; //original database
$database1 = "babynfcj_babymarket_staging"; // destination database

$stagingPath = "/home/babynfcj/projects/staging/BabyMarketStaging";
$productionPath= "/home/babynfcj/public_html";


/*
 * Синхронизиране на Базата Данни
 */
$connect2 = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_);
mysql_select_db($database1, $connect2);
set_time_limit(0);

$connect = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_);
mysql_select_db($database, $connect);

$tables = mysql_query("SHOW TABLES FROM $database");
while($line = mysql_fetch_row($tables)) {
    $tab = $line[0];
    mysql_query("DROP TABLE IF EXISTS $database1.$tab");
    mysql_query("CREATE TABLE $database1.$tab LIKE $database.$tab") or die(mysql_error());
    mysql_query("INSERT INTO $database1.$tab SELECT * FROM $database.$tab");
    echo "Table: <b>" . $line[0] . " </b>Done<br>";
}


/*
 * Синхронизиране на файловете
 */
shell_exec ("rsync -acz {$productionPath}/img {$stagingPath}"); // Sync Images

?>